//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System.ComponentModel;
using System.Workflow.ComponentModel;
using System.Xml;

namespace Microsoft.Research.ScientificWorkflow.Activities
{
    [Name("HTML to XHTML Converter", "HTML to XHTML")]
    [Description("Converts an HTML file into a well formed XML and thus XHTML file.")]
    [WorkflowCategory("Utilities")]
    public partial class HtmlToXhtml : System.Workflow.ComponentModel.Activity
    {
        #region Property Definitions
        // Required input properties
        public static DependencyProperty HtmlSourceProperty =
            DependencyProperty.Register("HtmlSource", typeof(string), typeof(HtmlToXhtml));
        // Output property
        public static DependencyProperty XhtmlProperty =
            DependencyProperty.Register("Xhtml", typeof(XmlDocument), typeof(HtmlToXhtml));

        [RequiredInputParam]
        [Name("HTML Source", "HTML")]
        [Description("The source of an html web page to be used for conversion to xhtml")]
        public string HtmlSource
        {
            get { return ((string)(base.GetValue(HtmlToXhtml.HtmlSourceProperty))); }
            set { base.SetValue(HtmlToXhtml.HtmlSourceProperty, value); }
        }

        [OutputParam]
        [Name("XHTML")]
        [Description("The resulting xhtml document")]
        public XmlDocument Xhtml
        {
            get { return ((XmlDocument)(base.GetValue(HtmlToXhtml.XhtmlProperty))); }
        }
        #endregion

        public HtmlToXhtml()
		{
			InitializeComponent();
		}

        /// <summary>
        /// Creates the XHTML document by attempting a conversion on the HTML source
        /// </summary>
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            /*
            StringReader strReader = new StringReader(HtmlSource);
            SgmlReader sgmlReader = new SgmlReader();
            sgmlReader.InputStream = strReader;
            sgmlReader.DocType = "HTML";
            XmlDocument xhtml = new XmlDocument();
            xhtml.Load(sgmlReader);

            base.SetValue(HtmlToXhtml.XhtmlProperty, xhtml);
            */
            return ActivityExecutionStatus.Closed;
        }
	}
}
